package wifiunion.com.notice.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.Gravity;
import android.widget.RadioButton;

import wifiunion.com.notice.R;


/**
 * Created by Administrator on 2017/12/6.
 */

public class CustomRadioButton extends RadioButton {

    private Drawable drawable;

    public CustomRadioButton(Context context) {
        super(context);
    }

    public CustomRadioButton(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomRadioButton(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Drawable[] drawables = getCompoundDrawables();
        if (drawables != null) {
            drawable = drawables[0];
        }
        int gravity = getGravity();
        int left = 0;
        if (gravity == Gravity.CENTER) {
            left = (int) getResources().getDimension(R.dimen.dp_20);
        }
        drawable.setBounds(left, 0, left + drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());

    }


}
